package com.zhuchaooasystem.presenter.home.ordertrack;

import android.app.Activity;

import com.zhuchaooasystem.api.HttpFactory;
import com.zhuchaooasystem.api.RxResultHelper;
import com.zhuchaooasystem.base.BasePresenter;
import com.zhuchaooasystem.base.SchedulersCompat;
import com.zhuchaooasystem.entity.OrderDetailEntity;
import com.zhuchaooasystem.entity.OrderTrackEntity;

import java.util.HashMap;
import java.util.Map;

import rx.Subscription;
import rx.functions.Action1;

/**
 * Created by zhangyajiang on 2016/12/22.
 */

public class OrderTrackPresenter extends BasePresenter<OrderTrackContract.View> implements OrderTrackContract.Presenter {

    public OrderTrackPresenter(Activity activity, OrderTrackContract.View view) {
        super(activity, view);
    }

    @Override
    public void downOrderTrack(String orderID) {
        Map<String, String> map = new HashMap<>();
        map.put("orderid", orderID);
        map.put("SystemNUm", "IOS");
        map.put("Version", "1.3.0");

        showLoading();
        Subscription subscription = HttpFactory.getHttpApi().orderTrack(map)
                .compose(SchedulersCompat.applyIoSchedulers())
                .compose(RxResultHelper.handleResult())
                .subscribe(new Action1<Object>() {
                    @Override
                    public void call(Object o) {

                        OrderTrackEntity entity = (OrderTrackEntity) o;

                        if (entity != null) {
                            mView.showOrderTrack(entity);
                        }

                        LoadingDiaogDismiss();

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {

                        LoadingDiaogDismiss();

                        handleError(throwable);
                    }
                });
        addSubscrebe(subscription);
    }
}
